#include "precom.h"
#include "StationaryShader.h"

StationaryShader::StationaryShader()
{
	cg_toolDirection = NULL;
	cg_toolPosFrag = NULL;
}

bool StationaryShader::CgShaderInit(HWND a_hWnd, CGcontext a_cg_context, CGprofile a_cg_vertProfile, CGprofile a_cg_fragProfile)
{
	cg_vertProg = cgCreateProgramFromFile(a_cg_context, CG_SOURCE, "Res/stationary.cg",
					a_cg_vertProfile, "vertshader2", 0);
	if( cg_vertProg == NULL ) {
		CGerror err = cgGetError();
		MessageBoxA(a_hWnd, cgGetErrorString(err), "Error StatVertCG", MB_OK);
		return false;
	}
	cg_fragProg = cgCreateProgramFromFile(a_cg_context, CG_SOURCE, "Res/stationary.cg",
					a_cg_fragProfile, "fragshader2", 0);
	if( cg_fragProg == NULL ) {
		CGerror err = cgGetError();
		MessageBoxA(a_hWnd, cgGetErrorString(err), "Error StatFragCG", MB_OK);
		return false;
	}
	
	cgGLLoadProgram(cg_vertProg);
	cgGLLoadProgram(cg_fragProg);
	
	cg_modelViewMatrix = cgGetNamedParameter(cg_vertProg, "ModelView");
	cg_modelViewProjMatrix = cgGetNamedParameter(cg_vertProg, "ModelViewProj");
	//cg_toolPos = cgGetNamedParameter(cg_vertProg, "ToolPos");
	//cg_toolAxis = cgGetNamedParameter(cg_vertProg, "ToolAxis");
	cg_toolPosFrag = cgGetNamedParameter(cg_fragProg, "ToolPosition");
	cg_toolDirection = cgGetNamedParameter(cg_fragProg, "ToolDirection");
	return true;
}

std::vector<boost::function<void(const fmath::vector3&)>> StationaryShader::SignUpForVecInfo()
{
	std::vector<boost::function<void(const fmath::vector3&)>> ret;
	ret.resize(ShaderExternalVecDataNum, NULL);
	ret[CgEnum_ToolPos] = boost::bind(&StationaryShader::SetToolPos, &(*this), _1);
	ret[CgEnum_ToolAxis] = boost::bind(&StationaryShader::SetToolAxis, &(*this), _1);
	return ret;
}

std::vector<boost::function<void(float)>> StationaryShader::SignUpForFloatInfo()
{
	std::vector<boost::function<void(float)>> ret;
	ret.resize(ShaderExternalFloatDataNum, NULL);
	return ret;
}